
function listAdd(%list, %entry){
	%entry = trim(%entry);
	if(!listContains(%list, %entry)){
		%listnew = trim(%list SPC %entry);
		return %listnew;
	}else{
		return %list;
	}
}

function listRemove(%list, %entry){
	%widx = listIndex(%list, %entry);
	if(%widx != -1){
		%lastword = getWord(%list, getWordCount(%list)-1);
		%list2 = setWord(%list, %widx, %lastword);
		%list3 = setWord(%list2, getWordCount(%list2)-1, "");
		%listnew = trim(%list3);
		return %listnew;
	}else{
		return %list;
	}
}

function listIndex(%list, %entry){
	for(%widx=0; %widx<getWordCount(%list); %widx++){
		%word = getWord(%list, %widx);
		if(%word == %entry){
			return %widx;
		}
	}
	return -1;
}

function listContains(%list, %entry){
	return listIndex(%list, %entry) != -1;
}
